package com.bwhx.eruler.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.bwhx.eruler.bean.BuyerSdk;
import com.bwhx.eruler.bean.Department;
import com.bwhx.eruler.bean.Page;
import com.bwhx.eruler.dao.BuyerSdkDao;
import com.bwhx.eruler.dao.DepartmentDao;

/**
 * @Description:
 */
@Repository
public class BuyerSdkDaoImpl extends BaseDaoImpl<BuyerSdk> implements BuyerSdkDao {
	public BuyerSdkDaoImpl() {
		this.setNs("com.bwhx.eruler.mapper.BuyerSdkMapper.");
	}

	@Override
	public List<BuyerSdk> findByBuyerId(BuyerSdk buyerSdk) {
		return getSqlSession().selectList(this.getNs() + "findByBuyerId", buyerSdk);

	}
	
	@Override
	public List<BuyerSdk> list(Page p) {
		return getSqlSession().selectList(this.getNs()  + "list",p);

	}

	@Override
	public Integer count(BuyerSdk bs) {
		Object selectOne = getSqlSession().selectOne(this.getNs() + "count",bs);
		if(null!=selectOne && selectOne instanceof Integer){
			return (int)selectOne;
		}
		return 0;
	}

	@Override
	public List<BuyerSdk> select(BuyerSdk buyerSdk) {
		return getSqlSession().selectList(this.getNs()  + "selectBySdkIdAndpwd",buyerSdk);

		
	}

	@Override
	public String getCouter(BuyerSdk buyerSdk) {
		
/*		String formatSN = String.format("%06d", rsnInt);
*/		
		Object selectOne = getSqlSession().selectOne(this.getNs() + "counter",buyerSdk);
		if(null!=selectOne && selectOne instanceof Integer){
			return String.format("%03d", (int)selectOne+1);
		}
		return "001";
	}

	@Override
	public List<BuyerSdk> findBySdkId(BuyerSdk buyerSdk) {
		return getSqlSession().selectList(this.getNs()  + "selectBySdkId",buyerSdk);
	}

	@Override
	public List<BuyerSdk> findByBuerIdAndEndTimeAndType(BuyerSdk buyerSdk) {
		return getSqlSession().selectList(this.getNs()  + "findByBuerIdAndEndTimeAndType",buyerSdk);
	}

	@Override
	public void updateDevInfosAndDevCount(String sdkId, String devinfo) {
		
		HashMap<String,String> paramMap = new HashMap<>();
		paramMap.put("sdkId", sdkId);
		paramMap.put("devinfo", devinfo);
		
		Object selectOne = getSqlSession().selectOne(this.getNs() + "selectdevinfo",paramMap);
		if(selectOne==null){
			this.getSqlSession().update(this.getNs()  + "updateDevInfosAndDevCount",paramMap);
		}
		

	}
		
}


	/*public List<Department> findByName(String deptname) {
	
		return getSqlSession().selectList("com.bwhx.eruler.mapper.DepartmentMapper." + "findByName", deptname);
	}


	

	@Override
	public void inputDepartment(Department d) {
		this.getSqlSession().update("com.bwhx.eruler.mapper.DepartmentMapper." + "updateruler", d);
		
		
	}




	@Override
	public List<Department> deptListAll() {
		return getSqlSession().selectList("com.bwhx.eruler.mapper.DepartmentMapper." + "listAll");

	}
	*/

